/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package services;

import javax.persistence.EntityManager;
import services.interfaces.IOrdersService;
import java.util.Date;
import java.util.List;
import javax.persistence.PersistenceContext;
import javax.validation.ConstraintDeclarationException;
import javax.validation.ConstraintViolationException;
import models.Baskets;
import models.Orders;
import models.Tables;
import models.Users;

/**
 *
 * @author amega
 */
public class OrdersServiceImpl extends GenericServiceImpl<Orders> implements IOrdersService {

    
    @PersistenceContext(unitName="ors-ejbPU2")
    private EntityManager em;
    
    public OrdersServiceImpl() {
        super(Orders.class);
    }
    
    
    @Override
    public double getOrdersPrice(Orders order) {
        return (double)em.createNamedQuery("Orders.getOrderPrice").setParameter("id_order", order.getId()).getFirstResult() ;
    }

    @Override
    public List<Orders> getUserOrders(Users user) {
        return (List<Orders>)em.createQuery("Orders.getUserOrders").setParameter("id_user", user.getId()).getResultList();
    }


    @Override
    public List<Tables> getOrderedTables(Date dateTime) {
        
        return null;
    }

    @Override
    protected EntityManager getEntityManager() {
       return  em;
    }

    @Override
    public int count() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void addOrdersBasket(Orders order, Baskets basket) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void OrdersTable(Orders order, Tables table) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
}
